package com.xxl.job.core.commons.annotation.impl;

import com.alibaba.fastjson.JSONObject;
import com.xxl.job.core.commons.annotation.MustEmpty;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @Description : 为空校验
 * @Author : tanxingsong
 * @Date : 15:21 2019/2/26
 * @Email : tanxingsong@cetcbigdata.com
 */
public class MustEmptyImpl implements ConstraintValidator<MustEmpty, Object> {
    @Override
    public void initialize(MustEmpty mustEmpty) {

    }

    @Override
    public boolean isValid(Object value, ConstraintValidatorContext context) {
        if (null == value || "".equals(JSONObject.toJSONString(value))) {
            return true;
        } else {
            return false;
        }
    }

}
